//字符串倒序
// Write a function that takes a string as input and returns the string reversed.

// Example:
// Given s = "hello", return "olleh".
var reverseString = function(s) {
    return s.split('').reverse().join('');
};

//字符串中元音字母倒序
// Write a function that takes a string as input and reverse only the vowels of a string.

// Example 1:
// Given s = "hello", return "holle".

// Example 2:
// Given s = "leetcode", return "leotcede".

var reverseVowels = function(s) {
    var reg = /[auoeiAUOEI]/,
        newStr = s.split(''),
        len = newStr.length,
        arr = [],
        vowels = [],
        start = 0,
        end = 0,
        i;
    for(i = 0; i < len; i++){
        if(reg.test(newStr[i])){
            vowels.push(i);
        }
    }
    start = 0;
    end = vowels.length - 1;
    while(start < end){
        var sIndex = vowels[start],
            eIndex = vowels[end],
            temp = newStr[sIndex];
        newStr[sIndex] = newStr[eIndex];
        newStr[eIndex] = temp;
        start ++;
        end --;
    }
    return newStr.join('');
};